/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.logistics.service.outboundorder;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.custom.service.CodeRuleService;
import com.jeesite.modules.file.utils.FileUploadUtils;
import com.jeesite.modules.logistics.dao.outboundorder.OutboundOrderDao;
import com.jeesite.modules.logistics.entity.outboundorder.OutboundOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 出库单Service
 * @author LV
 * @version 2021-03-10
 */
@Service
@Transactional(readOnly=true)
public class OutboundOrderService extends CrudService<OutboundOrderDao, OutboundOrder> {

    @Autowired
    private CodeRuleService codeRuleService;

	/**
	 * 获取单条数据
	 * @param outboundOrder
	 * @return
	 */
	@Override
	public OutboundOrder get(OutboundOrder outboundOrder) {
		return super.get(outboundOrder);
	}
	
	/**
	 * 查询分页数据
	 * @param outboundOrder 查询条件
	 * @param outboundOrder.page 分页对象
	 * @return
	 */
	@Override
	public Page<OutboundOrder> findPage(OutboundOrder outboundOrder) {
		return super.findPage(outboundOrder);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param outboundOrder
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(OutboundOrder outboundOrder) {
        if (outboundOrder.getIsNewRecord()){
            outboundOrder.setOutboundOrderCode(codeRuleService.getCode("outboundorder"));
        }
		super.save(outboundOrder);
        if (outboundOrder.getIsNewRecord()){
            codeRuleService.updateCurrentNumber("outboundorder");
        }
		// 保存上传附件
		FileUploadUtils.saveFileUpload(outboundOrder.getId(), "outboundOrder_file");
	}
	
	/**
	 * 更新状态
	 * @param outboundOrder
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(OutboundOrder outboundOrder) {
		super.updateStatus(outboundOrder);
	}
	
	/**
	 * 删除数据
	 * @param outboundOrder
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(OutboundOrder outboundOrder) {
		super.delete(outboundOrder);
	}
	
}